package com.cell.controller;

import com.cell.common.Result;
import com.cell.common.States;
import com.cell.common.exceptions.exceptions.PointRewardException;
import com.cell.pojo.entity.system.PointReward;
import com.cell.service.system.IPointRewardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cloudJiang
 * @date 2022/6/27 19:21
 */
@RestController
@RequestMapping("/api.product")
@Api(tags = "积分商品相关接口")
public class PointRewardController {
    @Autowired
    IPointRewardService pointRewardService;


    /**
     * 获取所有商品
     *
     * @return
     */

    @ApiOperation(value = "获取所有商品", notes = "获取数据库中的所有商品")
    @GetMapping("/getAllProducts")
    Result getAllProducts() {
        List<PointReward> pointRewards = pointRewardService.getBaseMapper().selectList(null);
        if (pointRewards.isEmpty()) {
            throw new PointRewardException(States.ERR_SELECT.getStates(), "获取所有商品失败，请稍后再试");
        }
        return new Result(pointRewards,
                States.OK.getStates(),
                States.OK.getDescription());
    }

}
